layui.use(['form', 'layer', 'jquery'], function () {
    var form = layui.form;
    var layer = layui.layer;
    var $ = layui.jquery;


     // 取消
    $("#closeBtn").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    })


    form.on('submit(addOrUpdateDept)', function (data) {
        var index = top.layer.msg("数据提交中", {
            icon: 16,
            title: false,
            shade: 0.8
        })

        var formData = data.field;
        var url = ctx + "/dept/add";
        var id = $("[name = 'id']").val();
        if (id != null && id != '') {
            url = ctx + "/dept/update";
        }
        $.post(url, formData, function (result) {
            if (result.code == 200) {
                top.layer.msg("操作成功", {icon: 6});
                top.layer.close(index);
                layer.closeAll("iframe");
                parent.location.reload();

            } else {
                layer.msg(result.msg, {icon: 6})
                top.layer.close(index);
            }
        })
        return false;
    })


})